package com.activemanager.healthGadget;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.activemanager.dashboard.H0Activity;
import com.activemanager.workoutAssistant.WorkoutAssistant_W1;
import com.example.android.navigationdrawerexample.R;
import com.example.android.navigationdrawerexample.R.drawable;
import com.example.android.navigationdrawerexample.R.id;
import com.example.android.navigationdrawerexample.R.layout;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;

public class HealthGadget  extends Activity {

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.test);
//		View rootView = inflater.inflate(R.layout.test, container, false);\
		
		initPic();
		
		ListView mGadgetList = (ListView) findViewById(R.id.gadget_list);
		String[] mFrom = new String[] { "profile_img", "profile_item" };
		String[] profileTitle = { "Daily Pulse Condition", "Foot Reader", "Weight Watcher", "S-Health Classic", "Air Qulity Index" };
		int[] mTo = new int[] { R.id.profile_img, R.id.profile_item };
		List<Map<String, Object>> mList = new ArrayList<Map<String, Object>>();
		Map<String, Object> mMap = null;
		for (int i = 0; i < profileTitle.length; i++) {
			mMap = new HashMap<String, Object>();
			int drawable = getResources().getIdentifier(
					"g" + (16 + i) + "_normal", "drawable",
					this.getPackageName());
			mMap.put("profile_img", drawable);
			mMap.put("profile_item", profileTitle[i]);
			mList.add(mMap);
		}
		SimpleAdapter mAdapter = new SimpleAdapter(this, mList,
				R.layout.gadget_list_item, mFrom, mTo);
		mGadgetList.setAdapter(mAdapter);
		mGadgetList.setOnItemClickListener(new OnItemClickListener()
		{

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
					long arg3) {
				// TODO Auto-generated method stub
				if(pos==1){
					Intent intent = new Intent();
					intent.setClass(HealthGadget.this,
							FootReader.class);
					startActivity(intent);
				}
			}
		});
		
		ImageView img_home = (ImageView) findViewById(R.id.imageView);
		img_home.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();
			}});
		
	}

	private void initPic() {
		// TODO Auto-generated method stub
		BitmapFactory.Options opt = new BitmapFactory.Options();
		opt.inPreferredConfig = Bitmap.Config.RGB_565;
		opt.inPurgeable = true;
		opt.inInputShareable = true;
		
		LinearLayout bgLayout = (LinearLayout) findViewById(R.id.relativeLayout);
//		InputStream is = getResources().openRawResource(
//				R.drawable.background_normal);
//		Bitmap bgbit = BitmapFactory.decodeStream(is, null, opt);
//		bgLayout.setBackgroundDrawable(new BitmapDrawable(bgbit));
		bgLayout.setBackgroundResource(R.drawable.bg_540);
	}
}
